package com.code.day05;

public class Ticket implements Runnable {
    int ticket = 100;
    final Object lock = new Object();
    @Override
    public void run() {
        for(;;)
        {
            try{
                Thread.sleep(100L);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            synchronized (lock){
                if(ticket > 0){
                    System.out.println(Thread.currentThread().getName() + "....买了第" + ticket-- + "张票");
                }
            }
            if(ticket == 0){
                return;
            }
        }
    }
}
